using System;
using System.Collections.Generic;
using System.Text;

namespace MapTestFramework.Common
{
    /// <summary>
    /// Represents a container of test data for testing a BizTalk Server map. The
    /// data is used to manipulate both the source and expected file templates 
    /// into the source and expected file. 
    /// </summary>
    public class MapTestCases
    {
        #region Constuctor And Initializing Members

        /// <summary>
        /// Initializes a new instance of the MapTestCases class with the specified source XPath expression.
        /// </summary>
        /// <param name="sourceXPath">XPath expression which identifies the node in the source file.</param>
        public MapTestCases(string sourceXPath) : this(sourceXPath, null)
        {
            return;
        }
        /// <summary>
        /// Initializes a new instance of the MapTestCases class with the specified source XPath and expected XPath expressions.
        /// </summary>
        /// <param name="sourceXPath">XPath expression which identifies the node in the source file.</param>
        /// <param name="expectedXPath">XPath expression which identifies the node in the expected file.</param>
        public MapTestCases(string sourceXPath, string expectedXPath)
        {
            ExceptionHelper.CheckEmptyOrNullValue(sourceXPath, "sourceXPath");

            m_SourceTestCaseValues = new TestCaseValueCollection(sourceXPath);
            if (expectedXPath != null)
                m_ExpectedTestCaseValues = new TestCaseValueCollection(
                    expectedXPath
                    );
            return;
        }
        /// <summary>
        /// Initializes a new instance of the MapTestCases class with the specified source XPath and expected XPath expressions.
        /// </summary>
        /// <param name="sourceXPaths">Array of XPath expressions which identify the nodes in the source file.</param>
        /// <param name="expectedXPaths">Array of XPath expressions which identify the nodes in the expected file.</param>
        public MapTestCases(string[] sourceXPaths, string[] expectedXPaths)
        {
            ExceptionHelper.CheckXPaths(sourceXPaths, "sourceXPaths");
            ExceptionHelper.CheckXPaths(expectedXPaths, "expectedXPaths");

            m_SourceTestCaseValues = new TestCaseValueCollection(sourceXPaths);
            if (expectedXPaths != null)
                m_ExpectedTestCaseValues = new TestCaseValueCollection(
                    expectedXPaths
                    );
            return;
        }

        #endregion

        #region Public Members

        private TestCaseValueCollection m_ExpectedTestCaseValues;
        private TestCaseValueCollection m_SourceTestCaseValues;

        /// <summary>
        /// Returns a collection of values used to update the expected file.
        /// </summary>
        public TestCaseValueCollection ExpectedTestCaseValues
        {
            get { return m_ExpectedTestCaseValues; }
        }
        /// <summary>
        /// Returns a collection of values used to update the source file.
        /// </summary>
        public TestCaseValueCollection SourceTestCaseValues
        {
            get { return m_SourceTestCaseValues; }
        }

        /// <summary>
        /// Adds a new test case with the specified source and expected values.
        /// </summary>
        /// <param name="sourceValues">Array of source values used to update the source file.</param>
        /// <param name="expectedValues">Array of source values used to update the expected file.</param>
        public void AddTestCase(string[] sourceValues, string[] expectedValues)
        {
            ExceptionHelper.CheckValues(
                sourceValues, m_SourceTestCaseValues.GetXPaths().Length, "sourceValues"
                );
            ExceptionHelper.CheckValues(expectedValues,
                m_ExpectedTestCaseValues.GetXPaths().Length, "expectedValues"
                );

            m_SourceTestCaseValues.Add(sourceValues);
            m_ExpectedTestCaseValues.Add(expectedValues);
            return;
        }
        /// <summary>
        /// Removes the test case at the specified index.
        /// </summary>
        /// <param name="index">Index of the test case.</param>
        public void RemoveTestCase(int index)
        {
            m_SourceTestCaseValues.RemoveAt(index);
            m_ExpectedTestCaseValues.RemoveAt(index);
            return;
        }

        #endregion

        #region Helper Members

        #endregion
    }
}
